<?php
/**
 * Created by PhpStorm.
 * Admininfo: Administrator
 * Date: 2018/1/22 0022
 * Time: 下午 8:41
 */
namespace app\admin\controller;
use app\common\controller\Curt;
use think\Config;
use think\Request;

class Img extends Curt{
    function __construct()
    {
        parent::__construct($upload = true,$uploadConfig = array(
            'input_name' => 'coverFile',//文本框name
            'data_field' => 'cover'//数据库字段
        ));
    }
    public function getall()
    {
        $del=input('?get.del');
        if($del){
            $list=$this->model->onlyTrashed()->paginate();
        }else{
            $list = $this->model->order('create_time desc')->paginate();
        }
        json_decode(json_encode($list));
        $page = $list->render();
        //print_r($list);die;
        $this->assign('list', $list);
        $this->assign('page', $page);
    }
    public function downurl(Request $request){
        $id=$request->param('id');
        $type = $request->param('type');
        $info=$this->model->find($id);
        $result=$info->toArray();
        if($type == 1){
            //下载源文件
            $file_name = $result['uploadspath'];
        }else{
            //下载转化文件
            $file_name = $result['transplantpath'];
        }
        $file_path=  $_SERVER['DOCUMENT_ROOT'].'\static\uploads'.$file_name;
        download($file_path);
    }
}